﻿Namespace EIBData.EIS
    Public NotInheritable Class EIBDataEIS_14
        Inherits EIBDataEIS_Base

        Protected _value As Byte = Nothing
        Protected _Svalue As SByte = Nothing


        Sub New(data As Byte())
            If Not CanEncode(data) Then Throw New EIB.Exceptions.EIBDataDecodeException("")

            MyBase._data = data
            _value = data(1)
            _Svalue = data(1)
        End Sub

        Sub New(value As Byte)
            _value = value
            _Svalue = Nothing
            MyBase._data = New Byte() {0, _value}
        End Sub

        Sub New(value As SByte)
            _value = Nothing
            _Svalue = value
            MyBase._data = New Byte() {0, _Svalue}
        End Sub


        Public Overrides Function CanEncode(data() As Byte) As Boolean
            Return data IsNot Nothing AndAlso data.Length = EIS_OctetLength
        End Function

        Public Overrides Function ToString() As String
            Return If(Not IsNothing(_value), _value, _Svalue)
        End Function

        Public Overrides Function ToObject() As Object()
            Return New Object() {If(Not IsNothing(_value), _value, _Svalue)}
        End Function

        Public Overrides ReadOnly Property ObjectType As System.Type()
            Get
                Return New Type() {If(Not IsNothing(_value), GetType(Byte), GetType(SByte))}
            End Get
        End Property

        Public Overrides Function ToInfoList() As List(Of EIB.InfoBase)
            Dim list As New List(Of EIB.InfoBase)

            list.Add(New EIB.Info("Type", EIS_Name))
            list.Add(New EIB.Info("Value (signed)", _Svalue))
            list.Add(New EIB.Info("Value (unsigned)", _value))

            Return list
        End Function

        Public Shared Shadows ReadOnly Property EIS_OctetLength As Byte
            Get
                Return 2
            End Get
        End Property

        Public Shared Shadows ReadOnly Property EIS_Name As String
            Get
                Return "EIS 14"
            End Get
        End Property


        Public ReadOnly Property Value As Byte
            Get
                Return _value
            End Get
        End Property

        Public ReadOnly Property SValue As SByte
            Get
                Return _Svalue
            End Get
        End Property
    End Class
End Namespace